package com.exam.controller;

import com.exam.dto.ActionResult;
import com.exam.dto.ExamAndPaper;
import com.exam.po.ExamManage;
import com.exam.po.Paper;
import com.exam.service.ExamService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author mahaoqi
 * @ClassName ExamController
 * @Description TODO
 * @Date 2021/1/12 14:45
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api")
public class ExamController {

    @Resource
    private ExamService examService;

    /*
     * @Author mahaoqi
     * @Description 添加考试+自动组卷
     * @Date 2021/1/13 10:42
     * @Param [data]
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping(value = "/addExam",method = RequestMethod.POST)
    public ActionResult addExam(@RequestBody ExamAndPaper eap){

//        System.out.println(paper);
//        System.out.println(form);


        Paper paper = eap.getPaper();
        ExamManage examManage = eap.getExamManage();
        Integer teacherid = eap.getTeacherid();
//        System.out.println(paper);
//        System.out.println(examManage);
//        System.out.println(teacherid);

        if(examService.addPaper(paper,examManage, teacherid)){
            return new ActionResult(200,"添加成功",null);
        }
        return new ActionResult(500,"添加失败",null);
    }

    /*
     * @Author mahaoqi
     * @Description 查找所有的考试  状态为  已审核
     * @Date 2021/1/13 10:42
     * @Param [teacherid, page, pageSize]
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping(value = "/findExamList/{teacherid}/{current}/{size}",method = RequestMethod.GET)
    public ActionResult findExamList(@PathVariable Integer teacherid,@PathVariable Integer current,@PathVariable Integer size){
        List<ExamManage>list = examService.findList(teacherid,current,size);
        Integer count = examService.findListCount(teacherid);
        System.out.println(list);
        Map data = new HashMap();
        data.put("data",list);
        data.put("total",count);
        if (data!=null){
            return new ActionResult(200,"查找成功",data);
        }
        return new ActionResult(500,"查找失败",null);
    }

    /*
     * @Author mahaoqi
     * @Description 查找所有的考试  状态为  未通过
     * @Date 2021/1/13 10:42
     * @Param [teacherid, page, pageSize]
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping(value = "/findExamNoList",method = RequestMethod.GET)
    public ActionResult findExamNoList(Integer teacherid,Integer page,Integer pageSize){
        List<ExamManage>list = examService.findNoList(teacherid,page,pageSize);
        if (list!=null){
            return new ActionResult(200,"查找成功",list);
        }
        return new ActionResult(500,"查找失败",null);
    }

    /*
     * @Author mahaoqi
     * @Description 修改考试信息    状态为 未通过的
     * @Date 2021/1/13 10:43
     * @Param [examManage]
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping(value = "/updateExam",method = RequestMethod.PUT)
    public ActionResult updateExam(@RequestBody  ExamManage examManage){
        if(examService.modifyExam(examManage)){
            return new ActionResult(200,"修改成功",null);
        }
        return new ActionResult(500,"修改失败",null);
    }


    /*
     * @Author mahaoqi
     * @Description 测试
     * @Date 2021/1/13 10:42
     * @Param []
     * @return com.exam.dto.ActionResult
     **/
    @RequestMapping(value = "/addExamTest",method = RequestMethod.POST)
    public ActionResult addExam1(){

        Paper paper = new Paper();
        paper.setPapername("计算机网络期末考试");
        paper.setSubject("计算机网络");
        paper.setFillNum(5);
        paper.setJudgeNum(5);
        paper.setMultiNum(5);
        ExamManage examManage = new ExamManage();
        examManage.setSubject("计算机网络");
        examManage.setDescription("2017年上期期末考试");
        examManage.setExamdate("2019-03-21");
        examManage.setTotalscore(101);
        examManage.setTotaltime(90);
        examManage.setGrade("2018");
        examManage.setMajor("计算机科学与技术");
        examManage.setInstitute("软件工程学院");
        examManage.setType("期末考试");
        examManage.setTips("快乐千万条，学习第一条，平时不努力，考试两行泪。");
        examManage.setStatus( "未通过");
        Integer teacherid = 20081002;
        if(examService.addPaper(paper,examManage, teacherid)){
            return new ActionResult(200,"添加成功",null);
        }
        return new ActionResult(500,"添加失败",null);
    }

//    {
//        "paper":{
//        "papername":"计算机网络qimo考试",
//                "subject": "计算机网络",
//                "fill_num":5,
//                "judge_num":5,
//                "multi_num":5
//    },
//        "examManage":{
//        "subject": "计算机网络",
//                "description": "2017年上期期末考试",
//                "examdate": "2019-03-21",
//                "totaltime": 120,
//                "grade": "2018",
//                "major": "计算机科学与技术",
//                "institute": "软件工程学院",
//                "totalscore": 101,
//                "type": "期末考试",
//                "tips": "快乐千万条，学习第一条，平时不努力，考试两行泪。",
//                "status": "未通过"
//    },
//        "teacherid":20081002
//
//    }
}
